﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Mengsk.ProxyDelivery.Print.UI"
             xmlns:model="clr-namespace:Mengsk.ProxyDelivery.Print.ViewModels" x:Class="Mengsk.ProxyDelivery.Print.UI.PrintHistoryUserControl" 
             mc:Ignorable="d"
            xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
             d:DesignHeight="300" d:DesignWidth="1400" Loaded="UserControl_Loaded">
    <Grid Grid.Column="1">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <StackPanel Grid.Row="0" Orientation="Horizontal" >
            <TextBlock Text="订单编号:" Margin="3" VerticalAlignment="Center"/>
            <TextBox Name="tbOrderId" Margin="3" VerticalAlignment="Center" Width="120"/>
            <TextBlock Text="卖家编号:" Margin="3" VerticalAlignment="Center"/>
            <TextBox Name="tbSellerId" Margin="3" VerticalAlignment="Center" Width="120"/>
            <TextBlock Text="快递公司:" Margin="3" VerticalAlignment="Center"/>
            <ComboBox Name="cbbDeliveryCompany" Margin="3" VerticalAlignment="Center" Width="120" DisplayMemberPath="DeliveryCompany"/>
            <TextBlock Text="运单编号:" Margin="3" VerticalAlignment="Center"/>
            <TextBox Name="tbDeliveryNumber" Margin="3" VerticalAlignment="Center" Width="120" />
            <TextBlock Text="开始时间:" Margin="3" VerticalAlignment="Center"/>
            <xctk:DateTimePicker Name="dpStart" Margin="3" VerticalAlignment="Center" Width="160" Format="Custom" FormatString="yyyy-MM-dd HH:mm:ss"/>
            <TextBlock Text="结束时间:" Margin="3" VerticalAlignment="Center"/>
            <xctk:DateTimePicker Name="dpEnd" Margin="3" VerticalAlignment="Center" Width="160"  Format="Custom" FormatString="yyyy-MM-dd HH:mm:ss"/>
            <Button Name="btnSearch" Content="查询" Margin="3" VerticalAlignment="Center" Width="60" Click="btnSearch_Click"/>
        </StackPanel>

        <TabControl Grid.Row="1" x:Name="tcOrderPages">
            <TabControl.ItemContainerStyle>
                <Style TargetType="{x:Type TabItem}">
                    <Setter Property="HeaderTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <TextBlock Text="{Binding DeliveryTitle}"/>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>

                    <Setter Property="ContentTemplate">
                        <Setter.Value>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto"/>
                                        <RowDefinition Height="*"/>
                                    </Grid.RowDefinitions>
                                    <StackPanel Grid.Row="0" Orientation="Horizontal">
                                        <CheckBox Content="全选" Margin="3" VerticalAlignment="Center" Checked="CheckBox_CheckedChanged" Unchecked="CheckBox_CheckedChanged" Tag="{Binding}"/>
                                        <TextBlock Text="当前共:" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Text="{Binding OrderViewModels.Count}" Margin="3" VerticalAlignment="Center"/>
                                        <TextBlock Text="新的物流公司:" Margin="3" VerticalAlignment="Center"/>
                                        <ComboBox x:Name="cbbDeliveryCompanies" Width="100" DisplayMemberPath="Name" VerticalAlignment="Center" ItemsSource="{Binding AllPrintTemplates, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:PrintHistoryUserControl}}}"/>
                                        <TextBlock Text="新的起始物流号:" Margin="3" VerticalAlignment="Center"/>
                                        <TextBox x:Name="tbNewDeliveryNumber" Margin="3" VerticalAlignment="Center" Width="100"/>
                                        <Button x:Name="btnAdjustDeliveryNumber" Content="修正单号" Margin="3" VerticalAlignment="Center" Width="80" Click="btnAdjustDeliveryNumber_Click" Tag="{Binding}"/>
                                        <Button Name="btnDelete" Content="删除记录" Margin="3" VerticalAlignment="Center" Click="btnDelete_Click" Width="80" Tag="{Binding}"/>
                                        <Button Name="btnUpload" Content="上传记录" Margin="3" VerticalAlignment="Center" Click="btnUpload_Click" Width="80" Tag="{Binding}"/>
                                        <Button Name="btnMarkPopDelivery" Content="标记发货" Margin="3" VerticalAlignment="Center" Click="btnMarkPopDelivery_Click" Width="80" Tag="{Binding}"/>
                                        <Button Name="btnRestPrintState" Content="重置打印" Margin="3" VerticalAlignment="Center" Click="btnRestPrintState_Click" Width="80" Tag="{Binding}"/>
                                    </StackPanel>
                                    <DataGrid ItemsSource="{Binding OrderViewModels}" Name="dgvItems" Grid.Row="1" IsReadOnly="True" Margin="3" HorizontalScrollBarVisibility="Auto"
											AutoGenerateColumns="False" 
											CanUserAddRows="False"
											CanUserDeleteRows="False"
											CanUserResizeRows="False"
											RowHeaderWidth="25"
											SelectionMode="Extended"
											SelectionUnit="CellOrRowHeader">
                                        <DataGrid.RowHeaderStyle>
                                            <Style TargetType="{x:Type DataGridRowHeader}">
                                                <Setter Property="ContentTemplate">
                                                    <Setter.Value>
                                                        <DataTemplate>
                                                            <CheckBox IsChecked="{Binding DataContext.IsChecked, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}}, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                                                        </DataTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </DataGrid.RowHeaderStyle>
                                        <DataGrid.RowStyle>
                                            <Style TargetType="{x:Type DataGridRow}">
                                                <Setter Property="Background" Value="{Binding Background}"/>
                                            </Style>
                                        </DataGrid.RowStyle>

                                        <DataGrid.ContextMenu>
                                            <ContextMenu>
                                                <MenuItem Header="向前选择" Name="miSelectPre" Click="miSelectPre_Click" Tag="{Binding ElementName=dgvItems,Path=SelectedCells}"/>
                                                <MenuItem Header="向后选择" Name="miSelectForward" Click="miSelectForward_Click" Tag="{Binding ElementName=dgvItems,Path=SelectedCells}"/>
                                            </ContextMenu>
                                        </DataGrid.ContextMenu>

                                        <DataGrid.Columns>
                                            <DataGridTextColumn Header="卖家编号" Binding="{Binding Source.SellerId}" Width="Auto"/>
                                            <DataGridTextColumn Header="订单编号" Binding="{Binding Source.OrderId}" Width="Auto"/>
                                            <DataGridTextColumn Header="物流编号" Binding="{Binding Source.WuliuId}" Width="Auto"/>
                                            <DataGridTextColumn Header="打印时间" Binding="{Binding Source.PrintTime,Converter={StaticResource datetimeConverter}}" Width="Auto"/>
                                            <DataGridTextColumn Header="上传时间" Binding="{Binding Source.UploadTime,Converter={StaticResource datetimeConverter}}" Width="Auto"/>
                                            <DataGridTextColumn Header="商品信息" Binding="{Binding Source.GoodsInfo}" Width="Auto"/>
                                            <DataGridTextColumn Header="礼品信息" Binding="{Binding Source.GiftInfo}" Width="Auto"/>
                                            <DataGridTextColumn Header="处理状态" Binding="{Binding State}" Width="Auto"/>
                                            <DataGridTextColumn Header="物流公司" Binding="{Binding DeliveryCompany}" Width="Auto"/>
                                            <DataGridTextColumn Header="快递单号" Binding="{Binding DeliveryNumber}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人姓名" Binding="{Binding Source.ReceiverName}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人电话" Binding="{Binding Source.ReceiverPhone}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人手机" Binding="{Binding Source.ReceiverMobile}" Width="Auto"/>
                                            <DataGridTextColumn Header="收件人地址" Binding="{Binding Source.ReceiverAddress}" Width="600"/>
                                        </DataGrid.Columns>
                                    </DataGrid>
                                </Grid>
                            </DataTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </TabControl.ItemContainerStyle>
        </TabControl>
    </Grid>
</UserControl>
